<template>
    <el-form :model="form" label-width="auto" style="max-width: 600px">
      <el-form-item label="学习计划:">
        <el-input v-model="form.title" />
      </el-form-item>
      <el-form-item label="是否完成:">
        <el-switch v-model="form.completed" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">添加</el-button>
        <el-button @click="myBack">返回</el-button>
      </el-form-item>
    </el-form>
  </template>
  
  <script setup>
  import { reactive } from 'vue'
  import {useRouter} from 'vue-router'
  import {addSchedule} from '../api/schedule.js'


  let router = useRouter()
  
  // do not use same name with ref
  const form = reactive({
    title:'',
    completed:false
  })
  
  const onSubmit =async () => {
    
    let {data} = await addSchedule(form)
    debugger
    if(data.code==200){
        router.push("/")
    }
  }
  const myBack=()=>{
    router.back()
  }
  </script>